package com.hspedu.newData.dmsxl.哈希表;

import org.junit.Test;

import java.util.HashMap;

/**
 * @Author: yh
 * @description: 
 * @CreateTime: 2025-04-22 
 * @Version: 1.0
 */

public class LC1两数之和 {

    public int[] twoSum(int[] nums, int target) {

        HashMap<Integer, Integer> hashMap = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            if (hashMap.containsKey(target - nums[i])){
                return new int[]{hashMap.get(target - nums[i]),i};
            }
            hashMap.put(nums[i],i);
        }
        return null;
    }


    @Test
    public void test() {
        // 测试代码

        twoSum(new int[]{2,7,11,15},9);
    }
}
